package com.gcb.service.impl;

import com.gcb.dao.CheckItemDao;
import com.gcb.entity.PageResult;
import com.gcb.pojo.CheckItem;
import com.gcb.service.CheckItemService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.dubbo.config.annotation.DubboService;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 35235
 * @Date 2021/8/3 17:46
 * @Version 1.0
 */
@DubboService(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    CheckItemDao checkItemDao;

    @Override
    public int add(CheckItem checkItem) {
        return checkItemDao.add(checkItem);
    }

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckItem> page = checkItemDao.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemDao.selectById(id);
    }

    @Override
    public int delete(Integer id) {
        int count = checkItemDao.delete(id);
        return count;
    }

    @Override
    public int updateById(CheckItem checkItem) {
        return checkItemDao.updateById(checkItem);
    }



    @Test
    public void test(){
        CheckItem checkItem = new CheckItem();
        checkItem.setCode("1022");
        checkItem.setSex("1");
        checkItem.setName("测试2");
        checkItem.setId(95);
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-dao.xml");
        CheckItemDao checkItemDao = (CheckItemDao) context.getBean("checkItemDao");
//        System.out.println(checkItemDao.selectByCondition("测试1"));
//        System.out.println(checkItemDao.selectById(95));
        System.out.println(checkItemDao.updateById(checkItem));
    }
}
